<template>
  <view>
    <CommonNavbar />
    <Tabbar :tab-list="tabList" fontSize="30rpx" defaultFontSize="26rpx" background="#f7f7f7"/>
    <view class="h-12rpx" />
    <enterpriseJobList :resume-list="resumeList"  />
    <up-popup
      :show="popupData.show"
      mode="center"
      :safe-area-inset-bottom="false"
      bg-color="transparent"
      @close="close"
      @open="open"
    >
      <view class="w-662rpx overflow-hidden rounded-24rpx bg-#fff">
        <view class="relative h-106rpx flex items-center justify-end px-24rpx">
          <text
            class="absolute left-50% top-50% translate-[-50%] text-center text-[28rpx] text-[#1d2129] font-medium"
          >
            {{ popupData.title }}
          </text>
          <up-icon
            :name="PopupClose"
            color="#f2f2f2"
            size="44rpx"
            @tap="popupData.show = false"
          />
        </view>
        <view>

        </view>
      </view>
    </up-popup>
  </view>
</template>

<script setup lang="ts">
import CommonNavbar from './components/v-navbar.vue';
// import PopupClose from '@/static/images/common/popup-close.png';
import enterpriseJobList from '@/pages/components/enterprise-job-list/index.vue';
import Tabbar from "@/pages/components/tabbar/index.vue";
// import home06 from "@/static/images/tab/home-06.png";
// import home10 from "@/static/images/tab/home-10.png";
import { userJobType, hrLookResumeList, userJobInteractionUpdate } from '@/api/user';
const PopupClose = "https://yiliao.test03.qcw800.com/static/images/common/popup-close.png";
const home06 = "https://yiliao.test03.qcw800.com/static/images/tab/home-06.png";
const home10 = "https://yiliao.test03.qcw800.com/static/images/tab/home-10.png";
const tabList = reactive([
    { name: '全部', activeLineWidth: 32*2},
]);
const options = ref<Record<string, string>>({});

const popupData = reactive({
  show: false,
  title: '',
  menuType: '',
});

const close = () => {};
const open = () => {};

const routerToResumeDetail = (resume_id: number) => {
  uni.navigateTo({
    url: '/pages/userinfo/resume-HRPerspective?resume_id='+resume_id,
  });
};

const onclickUserLike = async (index:number, resume_id:number, like: number) => {
  console.log('修改职位互动type:::', index, ' job_id:::', resume_id, ' like:::', like);

  const result = await userJobInteractionUpdate({
    like_hr: like == 1? 0 : 1,
    resume_id: resume_id,
  });
  console.log('修改hr互动result:::', result);
  resumeList[index].like_img = like == 1 ? home10 : home06;
  resumeList[index].like = like == 1 ? 0 : 1;
}
const resumeList:any = reactive([])
async function getHrLookResumeList(position_id: number) {
  let params:any = {}
  if (position_id != 0) {
    params['position_id'] = position_id;
  }
  resumeList.splice(0, resumeList.length);
  let result = await hrLookResumeList(params);
  console.log('找工作-hr查看职位列表 r:::', result);
  if (!result || !result.list) {
    return
  }
  for (let i = 0; i < result.list.length; i++) {
    let r = result.list[i]
    let rr = {
      resume_id: r.id,
      avatar: r.user.avatar,
      name: r.user.name,
      gender: r.user.gender,
      province: r.intention.province.name,
      city: r.intention.city.name,
      position_type: r.intention.position.p_content,
      position: r.intention.position.content,
      qualification: r.education.qualification,
      nature: r.intention.nature,
      highlights: r.highlights,
      like: r.like,
      like_img: r.like == 1 ? home06 : home10,
      school_name: r.education.school_name,
      college_name: r.education.college_name,
      majors_name: r.education.majors_name,
      status_overseas_study: '',
      heart_content: r.heart_content,
      have_other_hr: !!r.other_hr ? 1 : 0,
      other_hr_name: '',
      other_hr_avatar: '',
      other_hr_duty: '',
      have_teacher: !!r.teacherInfo ? 1 : 0,
      teacher_name: '',
      teacher_school_name: '',
      teacher_college_name: '',

    }
    if (r.status_overseas_study == 1) {
      rr.status_overseas_study = '留学'
    } else {
      rr.status_overseas_study = '未留学'
    }
    if (rr.have_other_hr == 1) {
      rr.other_hr_name = r.other_hr.name
      rr.other_hr_avatar = r.other_hr.avatar
      rr.other_hr_duty = r.other_hr.hr.duty.name
    }
    if (rr.have_teacher == 1) {
      rr.teacher_name = r.teacherInfo.name
      rr.teacher_school_name = r.teacherInfo.teacher.school.name
      rr.teacher_college_name = r.teacherInfo.teacher.college.name
    }
    resumeList.push(rr)
  }
}
async function getJobType() {
  let result = await userJobType();
  console.log('HR首页职位类型::', result);
  for (let i = 0; i < result.length; i++) {
    const r = result[i]
    if (r.level == 2) {
      tabList.push({
        id: r.id,
        name: r.content,
        activeLineWidth: r.content.length * 36+""
      })
    }
  }
  if (tabList.length > 0) {
    getHrLookResumeList(0);
  }
}
function tabChange(item) {
  console.log('点击item:::', item)
  getHrLookResumeList(item.id)
}

onLoad((params: any) => {
  options.value = params;
  getJobType()
});

</script>

<style scoped lang="scss"></style>
